import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../../model/model.dart';

///主题背景颜色
const Color Color_theme = Color(0xFFC5283B);

///子视图背景颜色
const Color Color_bg_view = Color(0xFFC0C0C0);

///边框颜色
const Color Color_border = Color(0xFF000000);

///按钮背景颜色
const Color Color_bg_btn = Color(0xFFC0C0C0);

///按钮选中颜色
const Color Color_select_btn = Color(0xFFC5283B);

///滑块圆点的颜色
const Color Color_thumb_slider = Color(0xFFC5283B);

///滑块，滑动过的颜色
const Color Color_active_slider = Color(0xFFC5283B);

///滑块，未滑动过的颜色
const Color Color_unActive_slider = Color(0xFF1A3C48);

///全局密码未输入 || enable == false 的状态颜色
const Color Color_disEnable = Color(0xFF727272);

///分段选择，默认为选中的背景颜色
const Color Color_grey_toggleBtn = Color(0xFF595757);
const Color Color_text = Colors.black;
const Color Color_text_select = Colors.white;

class GlobalConfig {
  static double scaleH = 0.0;
}

///背景颜色
Color bg_color(var model) {
  if (model is ChannelModel ||
      model is SignModel ||
      model is Passmodel ||
      model is GroupModel) {
    if (model.enable == false) {
      return const Color(0xFFC0C0C0);
    } else {
      return model.select ? const Color(0xFFC5283B) : const Color(0xFFC0C0C0);
    }
  }
  return const Color(0xFFC0C0C0);
}

///边框颜色
Color border_color(var model) {
  if (model is ChannelModel ||
      model is SignModel ||
      model is Passmodel ||
      model is GroupModel) {
    if (model.enable == false) {
      return Color_disEnable;
    } else {
      return model.select ? const Color(0xFFC5283B) : const Color(0xFF000000);
    }
  } else if (model is GlobalModel) {
    return model.enable ? Color_border : Color_disEnable;
  }
  return Color_border;
}

///文本颜色
Color text_color(var model, {Color selectColor = Colors.white}) {
  if (model is ChannelModel ||
      model is SignModel ||
      model is Passmodel ||
      model is GroupModel) {
    if (model.enable == false) {
      return Color_disEnable;
    } else {
      return model.select ? selectColor : Color_border;
    }
  } else if (model is GlobalModel) {
    return model.enable ? Color_border : Color_disEnable;
  }
  return Color_border;
}

class assets {
  static const String _basePath = 'assets/images/';

  static String getImagePath(String imageName) {
    return '$_basePath$imageName.png';
  }

  // 定义具体的图片资源
  static const String add = '${_basePath}add.png';
  static const String sum = '${_basePath}sum.png';
  static const String arrow_down = '${_basePath}arrow_down.png';
  static const String arrow_up = '${_basePath}arrow_up.png';
  static const String bg_chart = '${_basePath}bg_chart.png';
  static const String bg_nav = '${_basePath}bg_nav.png';
  static const String bg_slider = '${_basePath}bg_slider.png';
  static const String cross_select = '${_basePath}cross_select.png';
  static const String cross = '${_basePath}cross.png';
  static const String eq_select = '${_basePath}eq_select.png';
  static const String eq = '${_basePath}eq.png';
  static const String share = '${_basePath}share.png';
  static const String FOUR = '${_basePath}FOUR.png';
  static const String gain_select = '${_basePath}gain_select.png';
  static const String gain = '${_basePath}gain.png';
  static const String left_btn = '${_basePath}left_btn.png';
  static const String lock = '${_basePath}lock.png';
  static const String logo = '${_basePath}logo.png';

  static const String new_save = '${_basePath}new_save.png';
  static const String ONE = '${_basePath}ONE.png';
  static const String password = '${_basePath}password.png';
  static const String right_btn = '${_basePath}right_btn.png';
  static const String save = '${_basePath}save.png';
  static const String settings = '${_basePath}settings.png';

  static const String slider_p = '${_basePath}slider_p.png';
  static const String success = '${_basePath}success.png';
  static const String summing_select = '${_basePath}summing_select.png';
  static const String summing = '${_basePath}summing.png';

  static const String swipe_left = '${_basePath}swipe_left.png';
  static const String swipe_right = '${_basePath}swipe_right.png';

  static const String tab_bg = '${_basePath}tab_bg.png';
  static const String THREE = '${_basePath}THREE.png';

  static const String turn_off = '${_basePath}turn_off.png';
  static const String turn_on = '${_basePath}turn_on.png';
  static const String TWO = '${_basePath}TWO.png';
  static const String upload = '${_basePath}upload.png';
  static const String VOL = '${_basePath}VOL.png';

  ///读取本地文件
  static Future<Uint8List?> readBinFile(String fileName) async {
    try {
      // 读取 bin 文件
      ByteData data = await rootBundle.load('assets/$fileName');

      // 将 ByteData 转换为 Uint8List 并返回
      return data.buffer.asUint8List();
    } catch (e) {
      print('Error reading bin file: $e');
      return null;
    }
  }
}

// bool exitEnable = false;
// void exitApp() {
//   if (exitEnable) {
//     exit(0);
//   }
// }
